package com.petmagics.learnlayoutanimation;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LayoutAnimationController;
import android.view.animation.ScaleAnimation;
import android.widget.LinearLayout;

/**
 * 为线性布局(LinearLayout)添加动画效果
 */
public class LinearAnimationFm extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        LinearLayout root = (LinearLayout) inflater.inflate(R.layout.fragment_linear_animation, container, false);

        ScaleAnimation sa = new ScaleAnimation(0,1,0,1);
        sa.setDuration(350);

        LayoutAnimationController lac = new LayoutAnimationController(sa,0.5f);//第二个参数是布局内元素动画延时

        lac.setOrder(LayoutAnimationController.ORDER_REVERSE);

        root.setLayoutAnimation(lac);
        root.findViewById(R.id.btnBack).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getFragmentManager().popBackStack();
            }
        });

        return root;
    }
}
